<?php
/**
 * Created by PhpStorm.
 * User: Jason
 * Date: 2017/9/2
 * Time: 12:22
 */

namespace Api\Provider\Admin;

use Common\Util\HttpClient;
class QRCodeProvider
{
    public function getQrCode($param)
    {
        //step-1: 获取access_token
        $appid = C('WECHAT.appid');
        $app_secret = C('WECHAT.secret');
        $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $app_secret;
        $res = json_decode(HttpClient::get($url),true);
        $access_token = $res['access_token'];

        //step-2:
        $code_url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$access_token;

        $data = [
            'scene' => $param['scene'],
            'page' => $param['page']
        ];
        $post_data = json_encode($data);
        $result = HttpClient::post($code_url, $post_data);
        print_r($result);

        //生成二维码图片
        $filename = 'test.jpg';
        $file = fopen('Runtime/Uploads/'.$filename, 'w+');
        fwrite($file, $result);
        fclose($file);

    }

}